package com.douqu.game.core.entity;

import com.douqu.game.core.entity.Asset;
import com.douqu.game.core.entity.GameObject;
import com.douqu.game.core.entity.common.CommonData;
import com.douqu.game.core.entity.goods.GoodsProp;
import com.douqu.game.core.entity.sprite.Card;
import com.douqu.game.core.factory.DataFactory;
import com.douqu.game.core.util.LoadUtils;

import java.util.Arrays;

/**
 * 初始数据
 * Created by bean on 2017/7/14.
 */
public class InitData extends GameObject {

    /**
     * id	initAssets	initProps	initSoldiers	crystal	crystalGrow
     */
//    public String secondQueue;
//
//    public String thirdQueue;
//
//    public String fourthQueue;
//
//    /**
//     * 队列消耗
//     */
//    public List<QueueConsume> queueConsumes = new ArrayList<>();
    /** 初始水晶(水晶;最大水晶数量) */
    public String crystal;
    /** 水晶成长
     * 60;1000|180;500
     * 时间单位是毫秒，最后一组的时间是战斗一局的最长时间
     * 前60秒每秒增加1点，60-180秒每0.5秒增加1点
     * */
    public CommonData[] crystalGrow;
    /** 初始水晶数量 */
    public int curCrystal;
    /** 初始最大水晶数量 */
    public int maxCrystal;
    /**
     * 初始资源
     */
    public CommonData[] initAssets;
    /**
     * 初始道具
     */
    public CommonData[] initProps;
    /**
     * 初始兵种(这里的兵种全都初始成1级,其它没有初始化的全都是0级，需要碎片才能升到1级)
     */
    public int[] initCards;

    /**
     * 初始副本
     */
    public CommonData[] initInstance;

    /**
     * 初始关卡
     */
    public CommonData[] initLevel;

    public String masterModel;

    public int masterSkill;

    /**
     * 技能的一个X权值,计算伤害值的时候用
     */
    public float skillPlusX;

    @Override
    public void setVariable(String key, String value)
    {
        switch (key)
        {
//            case "secondQueue":
//            case "thirdQueue":
//            case "fourthQueue":
//                queueConsumes.add(new QueueConsume(value));
//                break;
//            case "initBuildingLv":
//                initBuildingLv = LoadUtils.loadResourceToArray(key,value);
//                break;


            case "initAssets":
                initAssets = LoadUtils.loadDataToArray(key, value);
                for(CommonData data : initAssets)
                {
                    Asset asset = DataFactory.getInstance().getGameObject(DataFactory.ASSET_KEY, data.id);
                    if(asset == null)
                    {
                        System.out.println("Load InitData Error: Asset is null! id=" + data.id);
                    }
                }
                break;
            case "initProps":
                initProps = LoadUtils.loadDataToArray(key, value);
                for(CommonData data : initProps)
                {
                    GoodsProp goodsProp = DataFactory.getInstance().getGameObject(DataFactory.GOODS_PROP_KEY, data.id);
                    if(goodsProp == null)
                    {
                        System.out.println("Load InitData Error: GoodsProp is null! id=" + data.id);
                    }
                }
                break;
            case "initCards":
                initCards = LoadUtils.loadIntArray(key, value);
                for(int id : initCards)
                {
                    Card card = DataFactory.getInstance().getGameObject(DataFactory.CARD_KEY, id);
                    if(card == null)
                    {
                        System.out.println("Load InitData Error: Card is null! id=" + id);
                    }
                }
                break;
            case "crystal":
                crystal = value;
                int[] ints = LoadUtils.loadIntArray(key, value);
                curCrystal = ints[0];
                maxCrystal = ints[1];
                break;
            case "crystalGrow":
                crystalGrow = LoadUtils.loadDataToArray(key, value);
                break;

            case "initInstance":
                initInstance = LoadUtils.loadDataToArray(key, value);
                for(CommonData data : initInstance)
                {
                    Asset asset = DataFactory.getInstance().getGameObject(DataFactory.INSTANCE_KEY, data.id);
                    if(asset == null)
                    {
                        System.out.println("Load InitData Error: Asset is null! id=" + data.id);
                    }
                }
                break;
            case "initLevel":
                initLevel = LoadUtils.loadDataToArray(key, value);
                for(CommonData data : initLevel)
                {
                    Asset asset = DataFactory.getInstance().getGameObject(DataFactory.LEVEL_KEY, data.id);
                    if(asset == null)
                    {
                        System.out.println("Load InitData Error: Asset is null! id=" + data.id);
                    }
                }
                break;
            default:
                super.setVariable(key,value);
                break;
        }

    }

    @Override
    public String toString() {
        return "InitData{" +
                "crystal='" + crystal + '\'' +
                ", crystalGrow=" + Arrays.toString(crystalGrow) +
                ", curCrystal=" + curCrystal +
                ", maxCrystal=" + maxCrystal +
                ", initAssets=" + Arrays.toString(initAssets) +
                ", initProps=" + Arrays.toString(initProps) +
                ", initCards=" + Arrays.toString(initCards) +
                ", masterModel='" + masterModel + '\'' +
                ", masterSkill=" + masterSkill +
                "} " + super.toString();
    }
}
